//
//  BK_SP_Type_Cell.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/3/31.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_SP_Type_Cell.h"
#import "BK_OD_Color.h"
#import <Masonry.h>

#define Width_PicLogo   20
#define Width_Btn       200
#define Width_Left      24
#define Height_Selected 111/2.0

@interface BK_SP_Type_Cell ()

@property (nonatomic,assign)NSInteger pay_type;
@end



@implementation BK_SP_Type_Cell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
    }
    return self;
}

- (void)initView{
    
    /*
     * 扣款账户
     */
    _lab_Count = [UILabel new];
    _lab_Count.textColor = kOrderBlack1;
    _lab_Count.font = [UIFont boldSystemFontOfSize:18];
    _lab_Count.numberOfLines=1;
    _lab_Count.text = @"扣款账户";
    _lab_Count.textAlignment=NSTextAlignmentCenter;
    _lab_Count.backgroundColor = [UIColor clearColor];
    [self addSubview:_lab_Count];
    [_lab_Count mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
        make.height.mas_equalTo(24);
    }];
    

    _view_line1 = [UILabel new];
    _view_line1.backgroundColor = kOrderLineGrey2;
    [self addSubview:_view_line1];
    [_view_line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_lab_Count.mas_bottom).offset(11);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.height.mas_equalTo(@(0.5));
    }];
    
    
    
    
    /*
     * 余额账户
     */
    _ImgV_Balance=[[UIImageView alloc]init];
    _ImgV_Balance.backgroundColor = [UIColor whiteColor];
    _ImgV_Balance.contentMode = UIViewContentModeScaleToFill;
    _ImgV_Balance.image=[UIImage imageNamed:@"BK_PayStore_YuE"];
    [self addSubview:_ImgV_Balance];
    [_ImgV_Balance mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_line1.mas_bottom).offset((Height_Selected-Width_PicLogo)/2.0);
        make.left.mas_equalTo(self.mas_left).offset(Width_Left);
        make.width.mas_equalTo(@(Width_PicLogo));
        make.height.mas_equalTo(@(Width_PicLogo));
    }];
    
    
    _lab_Balance = [UILabel new];
    _lab_Balance.textColor = kOrderBlack1;
    _lab_Balance.font = [UIFont systemFontOfSize:15];
    _lab_Balance.numberOfLines=1;
    _lab_Balance.text = @"余额账户";
    _lab_Balance.textAlignment=NSTextAlignmentLeft;
    _lab_Balance.backgroundColor = [UIColor clearColor];
    [self addSubview:_lab_Balance];
    [_lab_Balance mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_ImgV_Balance.mas_centerY);
        make.left.mas_equalTo(_ImgV_Balance.mas_right).offset(10);
        make.width.mas_equalTo(61.5+5);
    }];
    
    
    /*
     * 账户余额
     */
    _lab_BalanceNum = [UILabel new];
    _lab_BalanceNum.textColor = kOrderMediumGrey1;
    _lab_BalanceNum.font = [UIFont systemFontOfSize:15];
    _lab_BalanceNum.numberOfLines=1;
    _lab_BalanceNum.text = @"";
    _lab_BalanceNum.textAlignment=NSTextAlignmentLeft;
    _lab_BalanceNum.backgroundColor = [UIColor clearColor];
    [self addSubview:_lab_BalanceNum];
    [_lab_BalanceNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_lab_Balance.mas_centerY);
        make.left.mas_equalTo(_lab_Balance.mas_right).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
        
    }];

    
    
    _btn_Balance=[[UIButton alloc]init];
    _btn_Balance.backgroundColor=[UIColor clearColor];
    _btn_Balance.tag=10010;
    [_btn_Balance addTarget:self action:@selector(Btn_Selected:) forControlEvents:UIControlEventTouchUpInside];
    [_btn_Balance setImage:[UIImage imageNamed:@"BK_my_addressUnSelected"] forState:UIControlStateNormal];
    [_btn_Balance setImage:[UIImage imageNamed:@"BK_my_addressDefaultSelected"] forState:UIControlStateSelected];
    //button图片的偏移量，距上左下右分别(10, 10, 10, 60)像素点
    [_btn_Balance setImageEdgeInsets:UIEdgeInsetsMake(0, Width_Btn, 0, 0)];
    [_btn_Balance setSelected:YES];
    _pay_type=10;
    [self addSubview:_btn_Balance];
    [_btn_Balance mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_ImgV_Balance.mas_centerY);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
        make.width.mas_equalTo(Width_PicLogo+Width_Btn);
        make.height.mas_equalTo(Width_PicLogo);
    }];

    

    _view_line2 = [UILabel new];
    _view_line2.backgroundColor = kOrderLineGrey2;
    _view_line2.alpha = 0.5;
    [self addSubview:_view_line2];
    [_view_line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_ImgV_Balance.mas_bottom).offset((Height_Selected-Width_PicLogo)/2.0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(Width_Left);
        make.height.mas_equalTo(@(0.5));
    }];

    
    
    
    
    
    
    /*
     * 支付宝账户
     */
    _ImgV_Alipay=[[UIImageView alloc]init];
    _ImgV_Alipay.backgroundColor = [UIColor whiteColor];
    _ImgV_Alipay.contentMode = UIViewContentModeScaleToFill;
    _ImgV_Alipay.image=[UIImage imageNamed:@"BK_PayStore_zhufubao"];
    [self addSubview:_ImgV_Alipay];
    [_ImgV_Alipay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_line2.mas_bottom).offset((Height_Selected-Width_PicLogo)/2.0);
        make.left.mas_equalTo(self.mas_left).offset(Width_Left);
        make.width.mas_equalTo(@(Width_PicLogo));
        make.height.mas_equalTo(@(Width_PicLogo));
    }];
    
    
    _lab_Alipay = [UILabel new];
    _lab_Alipay.textColor = kOrderBlack1;
    _lab_Alipay.font = [UIFont systemFontOfSize:15];
    _lab_Alipay.numberOfLines=1;
    _lab_Alipay.text = @"支付宝账户";
    _lab_Alipay.textAlignment=NSTextAlignmentLeft;
    _lab_Alipay.backgroundColor = [UIColor clearColor];
    [self addSubview:_lab_Alipay];
    [_lab_Alipay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_ImgV_Alipay.mas_centerY);
        make.left.mas_equalTo(_ImgV_Alipay.mas_right).offset(10);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
    }];
    
    
    _btn_Alipay=[[UIButton alloc]init];
    _btn_Alipay.backgroundColor=[UIColor clearColor];
    _btn_Alipay.tag=10020;
    [_btn_Alipay addTarget:self action:@selector(Btn_Selected:) forControlEvents:UIControlEventTouchUpInside];
    [_btn_Alipay setImage:[UIImage imageNamed:@"BK_my_addressUnSelected"] forState:UIControlStateNormal];
    [_btn_Alipay setImage:[UIImage imageNamed:@"BK_my_addressDefaultSelected"] forState:UIControlStateSelected];
    //button图片的偏移量，距上左下右分别(10, 10, 10, 60)像素点
    [_btn_Alipay setImageEdgeInsets:UIEdgeInsetsMake(0, Width_Btn, 0, 0)];
    [_btn_Alipay setSelected:NO];
    [self addSubview:_btn_Alipay];
    [_btn_Alipay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_ImgV_Alipay.mas_centerY);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
        make.width.mas_equalTo(Width_PicLogo+Width_Btn);
        make.height.mas_equalTo(Width_PicLogo);
    }];
    
    
    
    _view_line3 = [UILabel new];
    _view_line3.backgroundColor = kOrderLineGrey2;
    [self addSubview:_view_line3];
    [_view_line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_ImgV_Alipay.mas_bottom).offset((Height_Selected-Width_PicLogo)/2.0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(Width_Left);
        make.height.mas_equalTo(@(0.5));
    }];


    /*
     * 微信账户
     */
    _ImgV_WeChat=[[UIImageView alloc]init];
    _ImgV_WeChat.backgroundColor = [UIColor whiteColor];
    _ImgV_WeChat.contentMode = UIViewContentModeScaleToFill;
    _ImgV_WeChat.image=[UIImage imageNamed:@"BK_PayStore_wechat"];
    [self addSubview:_ImgV_WeChat];
    [_ImgV_WeChat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_line3.mas_bottom).offset((Height_Selected-Width_PicLogo)/2.0);
        make.left.mas_equalTo(self.mas_left).offset(Width_Left);
        make.width.mas_equalTo(@(Width_PicLogo));
        make.height.mas_equalTo(@(Width_PicLogo));
    }];
    
    
    _lab_WeChat = [UILabel new];
    _lab_WeChat.textColor = kOrderBlack1;
    _lab_WeChat.font = [UIFont systemFontOfSize:15];
    _lab_WeChat.numberOfLines=1;
    _lab_WeChat.text = @"微信账户";
    _lab_WeChat.textAlignment=NSTextAlignmentLeft;
    _lab_WeChat.backgroundColor = [UIColor clearColor];
    [self addSubview:_lab_WeChat];
    [_lab_WeChat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_ImgV_WeChat.mas_centerY);
        make.left.mas_equalTo(_ImgV_WeChat.mas_right).offset(10);
        make.right.mas_equalTo(self.mas_right).offset(-100);
    }];
    
    
    _btn_WeChat=[[UIButton alloc]init];
    _btn_WeChat.backgroundColor=[UIColor clearColor];
    _btn_WeChat.tag=10030;
    [_btn_WeChat addTarget:self action:@selector(Btn_Selected:) forControlEvents:UIControlEventTouchUpInside];
    _btn_WeChat.userInteractionEnabled=YES;
    [_btn_WeChat setImage:[UIImage imageNamed:@"BK_my_addressUnSelected"] forState:UIControlStateNormal];
    [_btn_WeChat setImage:[UIImage imageNamed:@"BK_my_addressDefaultSelected"] forState:UIControlStateSelected];
    //button图片的偏移量，距上左下右分别(10, 10, 10, 60)像素点
    [_btn_WeChat setImageEdgeInsets:UIEdgeInsetsMake(0, Width_Btn, 0, 0)];
    [_btn_WeChat setSelected:NO];
    [self addSubview:_btn_WeChat];
    
    [_btn_WeChat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_ImgV_WeChat.mas_centerY);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
        make.width.mas_equalTo(Width_PicLogo+Width_Btn);
        make.height.mas_equalTo(Width_PicLogo);
    }];
    
    
    _view_line4 = [UILabel new];
    _view_line4.backgroundColor = kOrderLineGrey2;
    [self addSubview:_view_line4];
    [_view_line4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_ImgV_WeChat.mas_bottom).offset((Height_Selected-Width_PicLogo)/2.0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.height.mas_equalTo(@(0.5));
    }];
   

    if (ScreenHeight<700) {
        _view_line4.hidden=YES;
    }

    
}


-(void)Btn_Selected:(UIButton*)btn{
    
    if (_pay_type) {
        if (_pay_type==btn.tag-10000) {
            return;
        }
    }
    
    [self Btn_SelectedWithTag:btn.tag];
    [self Btn_click:btn.tag-10000];
    
}

-(void)Btn_SelectedWithTag:(NSInteger)tag{
    if (tag==10010) {
        [_btn_Balance setSelected:YES];
        [_btn_Alipay setSelected:NO];
        [_btn_WeChat setSelected:NO];
    }else if (tag==10020){
        [_btn_Balance setSelected:NO];
        [_btn_Alipay setSelected:YES];
        [_btn_WeChat setSelected:NO];
    }else if (tag==10030){
        [_btn_Balance setSelected:NO];
        [_btn_Alipay setSelected:NO];
        [_btn_WeChat setSelected:YES];
    }
    _pay_type=tag-10000;
}

-(void)Btn_click:(NSInteger)t{
    if ([self.delegate respondsToSelector:@selector(BK_SP_Type_clicked:)]) {
        [self.delegate BK_SP_Type_clicked:t];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+(CGFloat)computeHeight:(id)data{
    return 413/2.0;
}
-(void)relayOutUIWithMoney:(NSString *)money{
    if (money) {
        
        money=[NSString stringWithFormat:@"%@",money];
        
        money=[NSString stringWithFormat:@"¥%.2f",[money floatValue]];

        _lab_BalanceNum.text = money;
    }
    
}


-(void)SetNoMoney{

    [self Btn_SelectedWithTag:10020];
    [self Btn_click:20];
    _lab_Balance.textColor = kOrderMediumGrey1;
    _lab_Balance.alpha=0.7;
    _lab_BalanceNum.textColor = kOrderMediumGrey1;
    _lab_BalanceNum.alpha=0.7;
    _btn_Balance.hidden=YES;

}
@end


















